package com.yitiao.data_algorithms.leetcode.editor.cn;

import com.yitiao.data_algorithms.leetcode.editor.cn.base.ListNode;

class MergeInBetweenLinkedLists{
    // 2024-03-05 14:24:41
    public static void main(String[] args) {
        Solution solution = new MergeInBetweenLinkedLists().new Solution();
    }
    
    //leetcode submit region begin(Prohibit modification and deletion)
/**
 * Definition for singly-linked list.
 * public class ListNode {
 *     int val;
 *     ListNode next;
 *     ListNode() {}
 *     ListNode(int val) { this.val = val; }
 *     ListNode(int val, ListNode next) { this.val = val; this.next = next; }
 * }
 */
class Solution {
    public ListNode mergeInBetween(ListNode list1, int a, int b, ListNode list2) {
        ListNode head1 = list1;
        ListNode head2 = list1;
        while (a-->1){
            head1 = head1.next;
        }
        while (b-->0){
            head2 = head2.next;
        }
        head1.next = list2;
        while (list2.next!=null){
            list2 = list2.next;
        }
        ListNode next = head2.next;
        list2.next = head2.next;
        return list1;
    }
}
//leetcode submit region end(Prohibit modification and deletion)

}